package AsLayers
{
	import AsLayers.BaseType.LonLat;
	import AsLayers.BaseType.Pixel;
	
	import flash.display.DisplayObject;
	import flash.events.*;
	
	import mx.containers.Canvas;
	import mx.controls.Image;
	import mx.controls.Label;
	
	public class Marker
	{
		private var lonlat:LonLat
		private var displayUrl:String
		private var display:Canvas=new Canvas()
		private var drawn:Boolean=false
		private var clickEventHandle:Function
		private var data:Object
		//private var 
		public function Marker(lonlat:LonLat,displayUrl:String,labelName:String=null)
		{
			this.lonlat=lonlat
			this.displayUrl=displayUrl;
			var image:Image=new Image()
			image.load(this.displayUrl);
			this.display.addChild(image);
			//this.display.source=this.displayUrl;
			if(labelName!=null){
			   // var text:TextLineMetrics=this.display.measureHTMLText(labelName)
			    var textLabel:Label=new Label();
			    textLabel.htmlText=labelName; 
                this.display.addChild(textLabel)
			}
			   
		}
		public function setData(data:Object):void{
			this.data=data
		}
		public function getData():Object{
			return this.data
		}
		public function addEventListener(type:String, listener:Function):void{
			this[type+"EventHandle"]=listener
			this.display.addEventListener(type,this[type+"EventHandle"])
			
		}
		public function draw(px:Pixel):DisplayObject{
			this.display.x=px.x
			this.display.y=px.y
			if(this.drawn){
				return null
			}else{
	          this.drawn=true
              return this.display
			}

			
		}
		public function getLonLat():LonLat{
			return this.lonlat;
		}
		public function destroy():void{
			this.display.parent.removeChild(this.display);
			this.display=null
			this.lonlat=null
		}

	}
}